package com.ch06.ex03;

import org.apache.commons.lang.StringUtils;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;

/**
 * Created by zc on 2016/3/3.
 */
public class ReadFile {

    public static void main(String[] args) throws IOException {

        Path textPath = Paths.get("D:/", "test1.txt");
        Charset charset = Charset.forName("UTF-8");

        List<String> lines = Files.readAllLines(textPath,charset);

        Collections.sort(lines);

        List<String> orderIds = new ArrayList<>();

        for(int i=0; i<lines.size(); i++){
            orderIds.add("'"+lines.get(i).trim()+"'");
            if(i % 1000 == 0){
                String rsStr = StringUtils.join(orderIds,",");
                System.out.println(rsStr);
                orderIds = new ArrayList<>();
            }
        }

        String rsStr = StringUtils.join(orderIds,",");
        System.out.println(rsStr);

    }
}
